package net.huashitong.log.service;

import com.sirdc.modules.core.dao.BaseDao;
import com.sirdc.modules.sys.base.StringPKService;
import com.sirdc.modules.sys.service.SysTableService;
import net.huashitong.Project.entity.NewProjects;
import net.huashitong.log.dao.ProjectsLogDao;
import net.huashitong.log.entity.ProjectsLog;
import net.huashitong.user.entity.BnpUser;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProjectsLogService extends StringPKService<ProjectsLog> {

    @Autowired
    private ProjectsLogDao dao;
    @Autowired
    private SysTableService tableService;

    @Override
    protected BaseDao<ProjectsLog, String> getDao() {
        return dao;
    }

    @Override
    protected void beforeSave(ProjectsLog obj) {
        obj.setSysId(tableService.updateMaxSysId("t_bnp_projects_log", null));
    }


    /**
     * 保存项目日志
     *
     * @param projects
     */
    public void saveLog(NewProjects projects, String ip, BnpUser user) {
        ProjectsLog log = new ProjectsLog();
        BeanUtils.copyProperties(projects, log);
        log.setProjectId(projects.getSysId());
        log.setIp(ip);
        this.onPrePersist(log);
        this.beforeSave(log);
        log.setCreateUser(user.getSysId());
        this.saveObject(log);
        this.afterSave(log);
    }


}
